﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;

namespace CoreCms.Net.Languages
{
    public static class StringLocalizerExtensions
    {
        private static IStringLocalizer<LanguageResources>? _stringLocalizer;

        public static void SetStringLocalizer(this IStringLocalizer<LanguageResources> stringLocalizer)
        {
            _stringLocalizer = stringLocalizer;
        }

        public static string t(this string key)
        {
            if (_stringLocalizer == null) throw new InvalidOperationException("未初始化");
            return _stringLocalizer[key].Value;
        }
    }
}
